﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Diagnostics;

namespace Dot2Silverlight.Web
{
    public class GeneralFunctions
    {
        public string ExecuteCommandDot(string source_file, string target_file)
        {
            Process process = new Process();
            string errorMsg = "";

            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.FileName = Definitions.DOT_PATH;
            process.StartInfo.Arguments = " -Txdot \"" + source_file + "\" -o \"" + target_file + "\"";
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.UseShellExecute = false;

            process.Start();
            string output = process.StandardOutput.ReadToEnd();
            string error = process.StandardError.ReadToEnd();
            process.WaitForExit();

            if (error.Length > 0)
            {
                errorMsg = error;
            }
            return errorMsg;
        }
    }
}
